

package ccuserinterface;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;

import datamodels.Conference;
import datamodels.GlobalDataStore;
import datamodels.Role;
import datamodels.User;
/**
 * This frame; where the user pick a user story.
 * @author anthonysierra and rithy chhen
 *
 */
@SuppressWarnings("serial")
public class ChooseUserStory extends JFrame
{
	//just for testing. 
	private GlobalDataStore my_data_store;
	private Role my_role; 
	private JButton submit_manuscript_screen;
	private JButton reviewer_submit_review;
	private JButton make_manuscript_decision;
	private JButton view_manuscripts;
	private JButton assign_reviewer_to_manuscript;
	private Conference my_conference;
	private User my_user;
	private JButton my_back_btn;
	/**
	 * This will create the screen for choosing what you would like to do after you have signed in.
	 * @param the_role What they are entering in the program as
	 * @param the_conference what conference they are attending
	 * @param the_user The user who entered
	 * @param the_data_store the data store to modify.
	 */
	public ChooseUserStory(Role the_role, Conference the_conference, User the_user, GlobalDataStore the_data_store)
	{
		my_data_store = the_data_store;
		my_role = the_role;
		my_conference = the_conference;
		my_user = the_user;
		setPreferredSize(new Dimension(500, 400));
		setVisible(true);
		setLayout(null);
		setupGUI();
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setResizable(false);
		repaint();
		pack();
	}
	private void setupGUI()
	{
		//setup Manuscript button to scaled instance of "ButtonImages
		//a submit manuscript button.
		submit_manuscript_screen = ImageCreator.createButton("Submit a Manuscript", new Rectangle(10, 0, 250, 75));
		submit_manuscript_screen.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				dispose();
				//Pass in the conference along with the user the role and the global data store to be modified.
				new SubmittingFrame(my_conference, my_user, my_role, my_data_store);
			}
		});
		add(submit_manuscript_screen, this.getComponentCount()-1);
		//a reviewer submit manuscript button.
		reviewer_submit_review = ImageCreator.createButton("Submit a Review", new Rectangle(submit_manuscript_screen.getBounds().x,
				submit_manuscript_screen.getBounds().y + submit_manuscript_screen.getBounds().height + 10, 250, 75));

		reviewer_submit_review.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent e) {
						dispose(); 
						new SubmitAReviewScreen(my_data_store, my_role, my_conference, my_user);
						
					}
				});
		
		add(reviewer_submit_review);
		// a make decision button.
		make_manuscript_decision = ImageCreator.createButton("Decide on a Manuscript", new Rectangle(reviewer_submit_review.getBounds().x,
				reviewer_submit_review.getBounds().y + reviewer_submit_review.getBounds().height + 10, 250, 75));
		
		make_manuscript_decision.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if(my_data_store.getCurrentConference().getManuscripts().size() < 1)
				{
					JOptionPane.showMessageDialog(make_manuscript_decision.getParent(), "There are no manuscripts currently in the system.", "No Manuscripts", JOptionPane.INFORMATION_MESSAGE);
					return;
				}
				dispose(); 
				new ManuscriptListFrame(my_conference, my_user, my_data_store);
				
			}
		});
		add(make_manuscript_decision);
		//a view manuscript list button.
		view_manuscripts = ImageCreator.createButton("View Manuscripts", new Rectangle(make_manuscript_decision.getBounds().x,
				make_manuscript_decision.getBounds().y + make_manuscript_decision.getBounds().height + 10, 250, 75));
		view_manuscripts.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent e) {
						/*if(my_data_store.getCurrentConference().getManuscripts().size() < 1)
						{
							JOptionPane.showMessageDialog(make_manuscript_decision.getParent(), "There are no manuscripts currently in the system.", "No Manuscripts", JOptionPane.INFORMATION_MESSAGE);
							return;
						}*/
						dispose(); 
						new ViewManuscriptsPage(my_data_store, my_role, my_conference, my_user);
						
					}
				});
		//an assign manuscript to reviewer button.
		assign_reviewer_to_manuscript = ImageCreator.createButton(" Assign Reviewer to Manuscript", new Rectangle(250, 10, 250, 75));
		assign_reviewer_to_manuscript.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				
				dispose(); 
				new AssignReviewerToManuscript(my_data_store, my_role, my_conference, my_user);
			}
		});
		add(assign_reviewer_to_manuscript);
		
		//check the user, and allow the user to perform only the action they should be able to perform.
		assign_reviewer_to_manuscript.setEnabled(false);
		if (my_role == Role.PC) {
			assign_reviewer_to_manuscript.setEnabled(true);
			submit_manuscript_screen.setEnabled(false);
			reviewer_submit_review.setEnabled(false);
		} else if (my_role == Role.AUTHOR) {
			reviewer_submit_review.setEnabled(false);
			make_manuscript_decision.setEnabled(false);
			view_manuscripts.setEnabled(false);
			submit_manuscript_screen.setEnabled(true);
		}
		else {
			submit_manuscript_screen.setEnabled(false);
			make_manuscript_decision.setEnabled(false);
			view_manuscripts.setEnabled(false);
		}
		submit_manuscript_screen.setFocusPainted(false);
		add(view_manuscripts);
		
		//Setup back button
		my_back_btn = ImageCreator.createButton("  Go back", new Rectangle(330,300,100,40));
		my_back_btn.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				
				dispose(); 
				new ConferenceCreatorStart();		
			}
		});
		add(my_back_btn);
	}

}
